package tgc.edu.tms.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import tgc.edu.tms.custom.CommonRepository;
import tgc.edu.tms.entity.SysUser;
import tgc.edu.tms.entity.TtbRecord;

@Repository
public interface TtbRecordRepository extends CommonRepository<TtbRecord, Integer> {

	public List<TtbRecord> findByUserId(Integer id, Sort sort);

	public List<TtbRecord> findByUserAndTypeTwoAndState(SysUser user, String string, String string2);

	public List<TtbRecord> findByType(String string);

	public List<TtbRecord> findByTypeAndState(String string, String string2);

	public List<TtbRecord> findByTeacherAndSuspendTime(String username1, String day1);

	public TtbRecord findByUserAndSuspendTimeAndSection(SysUser user, String suspendTime, String section);

	public TtbRecord findByUserAndSuspendTimeAndSectionAndTypeTwoIsNull(SysUser user, String suspendTime,
			String section);

	@Query(value="from TtbRecord t  where t.opplyTime >= ?1 and t.opplyTime <= ?2 ")
	public List<TtbRecord> findOpplyTime(String opplyTime, String opplyTime1);

	//@Query(value = "select new TbSumWork(t.user,sum(t.amount),sum(t.salary),avg(t.paidState)) from TbSumWork t " + "where t.project=?1 " + "group by t.user " + "order by t.user.name")
   // public Page<TbSumWork> findSumByProject(TbProject project, Pageable pageable);
	
	@Query(value="SELECT new TtbRecord(t.user, t.type, count(t.id)) from TtbRecord t GROUP BY t.user,t.type")
	public Page<TtbRecord> findBytypeCount(PageRequest pageable);

	@Query(value="SELECT new TtbRecord(t.user, t.type, count(t.id)) from TtbRecord t where t.opplyTime >= ?1 and t.opplyTime <= ?2 GROUP BY t.user,t.type")
	public List<TtbRecord> findBytypeCount1(String op1, String op2);

}
